package net.gooduo.spring_boot_template.config;

import cn.dev33.satoken.exception.NotLoginException;
import net.gooduo.spring_boot_template.exception.HttpExceptionEnum;
import net.gooduo.spring_boot_template.http.HttpResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public HttpResult handlerException(Exception e) {
        if (e instanceof NotLoginException) {
            return HttpResult.error(HttpExceptionEnum.PLEASE_LOGIN);
        } else {
            e.printStackTrace();
        }
        return new HttpResult(1000, String.format("未知错误, %s", e.getMessage()), null);
    }
}